package com.ciei.dpagm.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ciei.dpagm.common.converter.JsonConverter;
import com.ciei.dpagm.common.enums.*;
import com.ciei.dpagm.common.enums.ErrorCodeEnum;
import com.ciei.dpagm.common.service.BaseService;
import com.ciei.dpagm.entity.*;
import com.ciei.dpagm.mapper.RuleSetMapper;
import com.ciei.dpagm.util.APP;
import com.ciei.dpagm.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
public class RuleSetService extends BaseService<RuleSetMapper, RuleSet> {

    @Autowired
    private RuleService ruleService;

    @Autowired
    private ConditionService conditionService;

    @Autowired
    private RuleSetParameterModuleService ruleSetParameterModuleService;

    @Autowired
    private ParameterService parameterService;

    @Autowired
    private ParameterModuleService parameterModuleService;

    @Autowired
    private ParameterModelService parameterModelService;

    @Autowired
    @Lazy
    private DriverLibraryService driverLibraryService;

    @Autowired
    private ChipPinService chipPinService;

    @Autowired
    private ChipInterfaceService chipInterfaceService;

    @Autowired
    private ChipClockParameterService chipClockParameterService;

    @Autowired
    private ChipPinParameterService chipPinParameterService;

    @Autowired
    private ChipInterfaceParameterService chipInterfaceParameterService;

    @Autowired
    private ChipParameterService chipParameterService;

    @Autowired
    private LogService logService;

    @Value("${baseFilePath}")
    private String baseFilePath;

    /**
     * 下拉框值分隔符，例:变量库和变量模块的value可能会相同，前端的下拉框组件没办法区分，使用@!切分
     */
    public static String optionValueSeparator = "@!";

    public static String modelIndex = "a";
    public static String moduleIndex = "b";
    public static String parameterTypeIndex = "c";
    public static String valueIndex = "d";

    /**
     * 获取条件关系下拉框列表
     * @return
     */
    public JSONObject getConditionalRelationOptionList() {
        ConditionalRelationEnum[] conditionalRelationEnums = ConditionalRelationEnum.values();
        List<JSONObject> dataList = new ArrayList<>();
        for (ConditionalRelationEnum conditionalRelationEnum : conditionalRelationEnums) {
            JSONObject data = new JSONObject();
            data.fluentPut("value", conditionalRelationEnum.getId())
                    .fluentPut("label", conditionalRelationEnum.getName());
            dataList.add(data);
        }
        return JsonUtil.getSuccess("").fluentPut(APP.DATA, dataList);
    }

    /**
     * 获取事实方式下拉框列表
     * @return
     */
    public JSONObject getFactModeOptionList(JSONObject webData) {
        List<Integer> parameterModuleIdList = webData.getJSONArray("parameterModuleIdList").toJavaList(Integer.class);
        List<JSONObject> parameterModuleOptionDataList = new ArrayList<>();
        List<JSONObject> parameterOptionDataList = new ArrayList<>();
        List<ParameterModule> parameterModuleList = parameterModuleService.findListByIds(parameterModuleIdList);
        Set<Integer> parameterModelIdSet = parameterModuleList.stream().map(ParameterModule::getParameterModelId).collect(Collectors.toSet());
        List<ParameterModel> parameterModelList = parameterModelService.findListByIds(parameterModelIdSet);
        List<Parameter> parameterList = parameterService.getListByModuleIdList(parameterModuleIdList);
        Map<Integer, Boolean> parameterDataTypeToIsCanSelectByRef = new HashMap<>();
        parameterDataTypeToIsCanSelectByRef.put(ParameterDataTypeEnum.ARRAY.getTypeId(),false);
        for(ParameterModel parameterModel : parameterModelList){
            List<ParameterModule> parameterModuleListByModelId = parameterModuleList.stream().filter(v -> parameterModel.getModelId().equals(v.getParameterModelId())).collect(Collectors.toList());
            List<JSONObject> parameterModuleDataList = new ArrayList<>();
            List<JSONObject> parameterModuleDataListByRef = new ArrayList<>();
            for(ParameterModule parameterModule : parameterModuleListByModelId){
                JSONObject parameterModuleData = new JSONObject();
                List<Parameter> parameterListByModuleId = parameterList.stream().filter(v -> parameterModule.getModuleId().equals(v.getParameterModuleId())).collect(Collectors.toList());
                List<Parameter> parentParameterListByModuleId = parameterListByModuleId.stream().filter(v -> Integer.valueOf("0").equals(v.getParentParameterId())).collect(Collectors.toList());
                List<Parameter> parameterListByModuleIdAndRef = parameterListByModuleId.stream().filter(p -> ParameterDataTypeEnum.OBJECT.equals(p.getDataType()) || ParameterDataTypeEnum.ARRAY.equals(p.getDataType())).collect(Collectors.toList());
                List<Parameter> parentParameterListByModuleIdAndRef = parameterListByModuleIdAndRef.stream().filter(p -> Integer.valueOf(0).equals(p.getParentParameterId())).collect(Collectors.toList());
                List<JSONObject> parameterOptionListByModuleIdAndRef = packageSonParameterDataList(parameterListByModuleIdAndRef, parentParameterListByModuleIdAndRef,valueIndex,parameterDataTypeToIsCanSelectByRef);
                parameterModuleData.fluentPut("value",moduleIndex + optionValueSeparator + parameterModule.getModuleId())
                        .fluentPut("label",parameterModule.getPropertyName())
                        .fluentPut("type",ConditionalTypeEnum.MODULE_DATA.getId())
                        .fluentPut("children",parameterOptionListByModuleIdAndRef);
                parameterModuleDataListByRef.add(JSONObject.parseObject(parameterModuleData.toJSONString()));
                List<JSONObject> parameterOptionListByModuleId = packageSonParameterDataList(parameterListByModuleId, parentParameterListByModuleId,valueIndex,null);
                parameterModuleData.fluentPut("children",parameterOptionListByModuleId);
                parameterModuleDataList.add(parameterModuleData);
            }
            JSONObject parameterOptionData = new JSONObject();
            parameterOptionData.fluentPut("value",modelIndex + optionValueSeparator + parameterModel.getModelId())
                    .fluentPut("label",parameterModel.getPropertyName())
                    .fluentPut("type",ConditionalTypeEnum.MODEL_DATA.getId());
            JSONObject parameterModuleOptionData = JSONObject.parseObject(parameterOptionData.toJSONString());
            if(!parameterModuleDataListByRef.isEmpty()){
                parameterModuleOptionData.fluentPut("children",parameterModuleDataListByRef);
            }
            if(!parameterModuleDataList.isEmpty()){
                parameterOptionData.fluentPut("children",parameterModuleDataList);
            }
            parameterModuleOptionDataList.add(parameterModuleOptionData);
            parameterOptionDataList.add(parameterOptionData);
        }
        FactModeEnum[] factModeEnums = FactModeEnum.values();
        List<JSONObject> dataList = new ArrayList<>();
        for (FactModeEnum factModeEnum : factModeEnums) {
            if (factModeEnum.getParentId().equals(0)) {
                JSONObject data = new JSONObject();
                data.fluentPut("value", factModeEnum.getId())
                        .fluentPut("label", factModeEnum.getName())
                        .fluentPut("type", ConditionalTypeEnum.FACT_MODE.getId());
                List<JSONObject> sonFactModeDataList = new ArrayList<>();
                packageSonFactModeDataList(factModeEnums, factModeEnum, sonFactModeDataList, parameterModuleOptionDataList, parameterOptionDataList);
                data.put("children", sonFactModeDataList);
                dataList.add(data);
            }

        }
        return JsonUtil.getSuccess("").fluentPut(APP.DATA, dataList);
    }

    /**
     * 组装子参数数据列表
     * @param allParameterList
     * @param parameterList
     * @return
     */
    public List<JSONObject> packageSonParameterDataList(List<Parameter> allParameterList, List<Parameter> parameterList, String valueIndex,Map<Integer, Boolean> parameterDataTypeToIsCanSelect) {
        List<JSONObject> parameterDataList = new ArrayList<>();
        for (Parameter parameter : parameterList) {
            JSONObject parameterData = new JSONObject();
            // 默认可选
            Boolean isCanSelect = true;
            if(parameterDataTypeToIsCanSelect != null && parameter.getDataType() != null){
                if(parameterDataTypeToIsCanSelect.get(parameter.getDataType().getTypeId()) != null){
                    isCanSelect = parameterDataTypeToIsCanSelect.get(parameter.getDataType().getTypeId());
                }
            }
            parameterData.fluentPut("value", valueIndex + optionValueSeparator + parameter.getParameterId())
                    .fluentPut("label", parameter.getParameterName() == null ? "" : parameter.getParameterName())
                    .fluentPut("type", ConditionalTypeEnum.VALUE_DATA.getId())
                    .fluentPut("isCanSelect",isCanSelect);
            List<Parameter> sonParameterList = allParameterList.stream().filter(p -> parameter.getParameterId().equals(p.getParentParameterId())).collect(Collectors.toList());
            char valueIndexChar = valueIndex.charAt(0);
            char nextChar = (char) (valueIndexChar + 1);
            String nextCharValue = String.valueOf(nextChar);
            List<JSONObject> sonParameterDataList = packageSonParameterDataList(allParameterList, sonParameterList, nextCharValue,parameterDataTypeToIsCanSelect);
            if (!sonParameterDataList.isEmpty()) {
                parameterData.fluentPut("children", sonParameterDataList);
            }
            parameterDataList.add(parameterData);
        }
        return parameterDataList;
    }


    /**
     * 组装子事实方式数据列表
     * @param factModeEnums
     * @param parentFactModeEnum
     * @param factModeDataList
     */
    public void packageSonFactModeDataList(FactModeEnum[] factModeEnums, FactModeEnum parentFactModeEnum, List<JSONObject> factModeDataList, List<JSONObject> parameterTypeOptionDataList, List<JSONObject> parameterOptionDataList) {
        for (FactModeEnum factModeEnum : factModeEnums) {
            if (parentFactModeEnum.getId().equals(factModeEnum.getParentId())) {
                JSONObject data = new JSONObject();
                List<JSONObject> sonFactModeDataList = new ArrayList<>();
                packageSonFactModeDataList(factModeEnums, factModeEnum, sonFactModeDataList, parameterTypeOptionDataList, parameterOptionDataList);
                data.fluentPut("value", factModeEnum.getId())
                        .fluentPut("label", factModeEnum.getName())
                        .fluentPut("type", ConditionalTypeEnum.FACT_MODE.getId());
                if (!sonFactModeDataList.isEmpty()) {
                    data.fluentPut("children", sonFactModeDataList);
                }
                if (FactModeEnum.getSelectParameterTypeFactModeIdList().contains(factModeEnum.getId())) {
                    if (!parameterTypeOptionDataList.isEmpty()) {
                        data.fluentPut("children", parameterTypeOptionDataList);
                    }
                }
                if (FactModeEnum.getSelectParameterFactModeIdList().contains(factModeEnum.getId())) {
                    if (!parameterOptionDataList.isEmpty()) {
                        data.fluentPut("children", parameterOptionDataList);
                    }
                }
                factModeDataList.add(data);
            }
        }
    }

    /**
     * 获取事实方式对应比较符下拉框列表
     * @return
     */
    public JSONObject getFactModeToComparatorOptionList() {
        JSONObject containData = new JSONObject();
        containData.fluentPut("value", ComparatorEnum.CONTAIN.getId())
                .fluentPut("label", ComparatorEnum.CONTAIN.getName());
        JSONObject inSetData = new JSONObject();
        inSetData.fluentPut("value", ComparatorEnum.IN_SET.getId())
                .fluentPut("label", ComparatorEnum.IN_SET.getName());
        JSONObject equalData = new JSONObject();
        equalData.fluentPut("value", ComparatorEnum.EQUAL.getId())
                .fluentPut("label", ComparatorEnum.EQUAL.getName());
        JSONObject lessThanEqualData = new JSONObject();
        lessThanEqualData.fluentPut("value", ComparatorEnum.LESS_THAN_EQUAL.getId())
                .fluentPut("label", ComparatorEnum.LESS_THAN_EQUAL.getName());
        JSONObject greaterThanEqualData = new JSONObject();
        greaterThanEqualData.fluentPut("value", ComparatorEnum.GREATER_THAN_EQUAL.getId())
                .fluentPut("label", ComparatorEnum.GREATER_THAN_EQUAL.getName());
        FactModeEnum[] factModeEnums = FactModeEnum.values();
        JSONObject data = new JSONObject();
        for (FactModeEnum factModeEnum : factModeEnums) {
            List<JSONObject> comparatorOptionList = new ArrayList<>();
            switch (factModeEnum) {
                case ALL_KEY_NAME_SELECT_PARAMETER:
                    comparatorOptionList.add(containData);
                    break;
                case KEY_VALUE_DATA_TYPE_SELECT_PARAMETER:
                    comparatorOptionList.add(equalData);
                    break;
                default:
                    break;
            }
            data.fluentPut(factModeEnum.getId().toString(), comparatorOptionList);
        }
        return JsonUtil.getSuccess("").fluentPut(APP.DATA, data);
    }

    /**
     * 获取事实方式和比较符对应标准规范下拉框列表
     * @return
     */
    public JSONObject getFactModeAndComparatorToStandardSpecificationOptionList(JSONObject webData) {
        List<Integer> parameterModuleIdList = webData.getJSONArray("parameterModuleIdList").toJavaList(Integer.class);
        return getFactModeAndComparatorToStandardSpecificationOptionList(parameterModuleIdList);
    }
    /**
     * 获取事实方式和比较符对应标准规范下拉框列表
     * @return
     */
    public JSONObject getFactModeAndComparatorToStandardSpecificationOptionList(List<Integer> parameterModuleIdList) {
        List<JSONObject> parameterModelDataList = new ArrayList<>();
        List<ParameterModule> parameterModuleList = parameterModuleService.findListByIds(parameterModuleIdList);
        Set<Integer> parameterModelIdSet = parameterModuleList.stream().map(ParameterModule::getParameterModelId).collect(Collectors.toSet());
        List<ParameterModel> parameterModelList = parameterModelService.findListByIds(parameterModelIdSet);
        List<Parameter> parameterList = parameterService.getListByModuleIdList(parameterModuleIdList);
        for (ParameterModel parameterModel : parameterModelList) {
            List<ParameterModule> parameterModuleListByModelId = parameterModuleList.stream().filter(v -> parameterModel.getModelId().equals(v.getParameterModelId())).collect(Collectors.toList());
            List<JSONObject> parameterModuleDataList = new ArrayList<>();
            for (ParameterModule parameterModule : parameterModuleListByModelId) {
                JSONObject parameterModuleData = new JSONObject();
                List<Parameter> parameterListByModuleId = parameterList.stream().filter(v -> parameterModule.getModuleId().equals(v.getParameterModuleId())).collect(Collectors.toList());
                List<Parameter> parentParameterList = parameterListByModuleId.stream().filter(p -> Integer.valueOf(0).equals(p.getParentParameterId())).collect(Collectors.toList());
                List<JSONObject> parameterOptionList = packageSonParameterDataList(parameterListByModuleId, parentParameterList,valueIndex,null);
                parameterModuleData.fluentPut("value", moduleIndex + optionValueSeparator + parameterModule.getModuleId())
                        .fluentPut("label", parameterModule.getPropertyName())
                        .fluentPut("type", ConditionalTypeEnum.MODULE_DATA.getId());
                parameterModuleData.fluentPut("children", parameterOptionList);
                parameterModuleDataList.add(parameterModuleData);
            }
            JSONObject parameterModelData = new JSONObject();
            parameterModelData.fluentPut("value", modelIndex + optionValueSeparator + parameterModel.getModelId())
                    .fluentPut("label", parameterModel.getPropertyName())
                    .fluentPut("type", ConditionalTypeEnum.MODEL_DATA.getId());
            parameterModelData.fluentPut("children", parameterModuleDataList);
            parameterModelDataList.add(parameterModelData);
        }
        StandardSpecificationEnum[] standardSpecificationEnums = StandardSpecificationEnum.values();
        JSONObject selectParameterData = new JSONObject();
        for (StandardSpecificationEnum standardSpecificationEnum : standardSpecificationEnums){
            if(standardSpecificationEnum.getParentId().equals(0)) {
                JSONObject data = new JSONObject();
                data.fluentPut("value", standardSpecificationEnum.getId())
                        .fluentPut("label", standardSpecificationEnum.getName())
                        .fluentPut("type", ConditionalTypeEnum.STANDARD_SPECIFICATION.getId());
                if (StandardSpecificationEnum.SELECT_PARAMETER.getId().equals(standardSpecificationEnum.getId())) {
                    data.put("children", parameterModelDataList);
                    selectParameterData = data;
                    continue;
                }
            }
        }
        JSONObject data = new JSONObject();
        List<JSONObject> standardSpecificationOptionList = new ArrayList<>();
        standardSpecificationOptionList.add(selectParameterData);
        data.fluentPut(FactModeEnum.ALL_KEY_NAME_SELECT_PARAMETER.getId() + "-" + ComparatorEnum.CONTAIN.getId(),standardSpecificationOptionList);
        standardSpecificationOptionList = new ArrayList<>();
        standardSpecificationOptionList.add(selectParameterData);
        data.fluentPut(FactModeEnum.KEY_VALUE_DATA_TYPE_SELECT_PARAMETER.getId() + "-" + ComparatorEnum.EQUAL.getId(),standardSpecificationOptionList);
        return JsonUtil.getSuccess("").fluentPut(APP.DATA,data);
    }

    /**
     * 初始化
     * @param data
     * @return
     */
    public JSONObject init(JSONObject data) {
        Integer ruleSetId = data.getInteger("ruleSetId");
        return init(ruleSetId);
    }
    /**
     * 初始化
     * @param ruleSetId
     * @return
     */
    public JSONObject init(Integer ruleSetId){
        RuleSet ruleSet = findById(ruleSetId);
        if(ruleSet == null){
            return JsonUtil.getFail(ErrorCodeEnum.DATA_NOT_FOUND,"找不到对应的规则集数据，请检查传入的id是否有误");
        }
        List<RuleSetParameterModule> ruleSetParameterModuleList = ruleSetParameterModuleService.findByProperty(RuleSetParameterModule::getRuleSetId, ruleSetId);
        List<Integer> ruleSetParameterModuleIdList = ruleSetParameterModuleList.stream().map(RuleSetParameterModule::getParameterModuleId).collect(Collectors.toList());
        List<Rule> ruleList = ruleService.findByProperty(Rule::getRuleSetId, ruleSetId);
        List<Condition> conditionList = conditionService.getListByRuleSetId(ruleSetId);
        List<JSONObject> ruleDataList = new ArrayList<>();
        for(Rule rule : ruleList){
            JSONObject ruleData = new JSONObject();
            List<Condition> conditionListByRuleId = conditionList.stream().filter(c -> rule.getRuleId().equals(c.getRuleId())).collect(Collectors.toList());
            List<JSONObject> conditionDataList = new ArrayList<>();
            for(Condition condition : conditionListByRuleId){
                JSONObject conditionData = new JSONObject();
                conditionData.fluentPut("conditionId",condition.getConditionId())
                        .fluentPut("description",condition.getDescription() == null ? "" : condition.getDescription())
                        .fluentPut("comparator",condition.getComparator())
                        .fluentPut("factMode",JSONObject.parseArray(condition.getFactMode(), String.class))
                        .fluentPut("standardSpecification",JSONObject.parseArray(condition.getStandardSpecification(), String.class));
                conditionDataList.add(conditionData);
            }
            Rule prepositionRule = ruleList.stream().filter(r -> r.getRuleId().equals(rule.getPrepositionRuleId())).findFirst().orElse(null);
            JSONObject prepositionRuleData = new JSONObject();
            prepositionRuleData.fluentPut("value",rule.getPrepositionRuleId())
                    .fluentPut("label",prepositionRule == null || prepositionRule.getRuleName() == null ? "" : prepositionRule.getRuleName());
            ruleData.fluentPut("ruleId",rule.getRuleId())
                    .fluentPut("ruleName",rule.getRuleName() == null ? "" : rule.getRuleName())
                    .fluentPut("ruleRemark",rule.getRuleRemark() == null ? "" : rule.getRuleRemark())
                    .fluentPut("prepositionRuleData",prepositionRuleData)
                    .fluentPut("conditionalRelation",rule.getConditionalRelation())
                    .fluentPut("conditionDataList",conditionDataList);
            ruleDataList.add(ruleData);
        }
        JSONObject data = new JSONObject();
        data.fluentPut("ruleSetId",ruleSet.getRuleSetId())
                .fluentPut("ruleSetName",ruleSet.getRuleSetName() == null ? "" : ruleSet.getRuleSetName())
                .fluentPut("parameterModuleIdList",ruleSetParameterModuleIdList)
                .fluentPut("ruleDataList",ruleDataList);
        return JsonUtil.getSuccess("").fluentPut(APP.DATA,data);
    }

    /**
     * 更新
     * @param data
     * @param user
     * @return
     */
    @Transactional
    public JSONObject edit(JSONObject data,Users user){
        RuleSet updateRuleSet = new RuleSet();
        JsonConverter<RuleSet> jsonConverter = new JsonConverter<>();
        updateRuleSet = jsonConverter.convert(data, updateRuleSet);
        updateRuleSet.setUpdateUserId(user.getUserId());
        updateById(updateRuleSet);
        handleRuleSetData(data,updateRuleSet,user);
        return init(updateRuleSet.getRuleSetId());
    }

    /**
     * 处理规则集数据
     * @param data
     * @param updateRuleSet
     * @param user
     */
    public void handleRuleSetData(JSONObject data,RuleSet updateRuleSet,Users user){
        JSONArray ruleDataList = data.getJSONArray("ruleDataList");
        List<RuleSetParameterModule> oldRuleSetParameterModuleList = ruleSetParameterModuleService.findByProperty(RuleSetParameterModule::getRuleSetId, updateRuleSet.getRuleSetId());
        List<Integer> oldParameterModuleIdList = oldRuleSetParameterModuleList.stream().map(RuleSetParameterModule::getParameterModuleId).collect(Collectors.toList());
        JSONArray parameterModuleIdList = data.getJSONArray("parameterModuleIdList");
        List<RuleSetParameterModule> addRuleSetParameterModuleList = new ArrayList<>();
        for(int i = 0; i < parameterModuleIdList.size();i++){
            Integer parameterModuleId = parameterModuleIdList.getInteger(i);
            if(!oldParameterModuleIdList.contains(parameterModuleId)){
                RuleSetParameterModule ruleSetParameterModule = new RuleSetParameterModule();
                ruleSetParameterModule.setParameterModuleId(parameterModuleId);
                ruleSetParameterModule.setUpdateUserId(user.getUserId());
                ruleSetParameterModule.setRuleSetId(updateRuleSet.getRuleSetId());
                addRuleSetParameterModuleList.add(ruleSetParameterModule);
            }
        }
        List<Integer> deleteRuleSetParameterModuleIdList = new ArrayList<>();
        for(RuleSetParameterModule ruleSetParameterModule : oldRuleSetParameterModuleList){
            if(!parameterModuleIdList.contains(ruleSetParameterModule.getParameterModuleId())){
                deleteRuleSetParameterModuleIdList.add(ruleSetParameterModule.getRuleSetParameterModuleId());
            }
        }

        List<Rule> oldRuleList = ruleService.findByProperty(Rule::getRuleSetId, updateRuleSet.getRuleSetId());
        List<Condition> oldConditionList = conditionService.findByProperty(Condition::getRuleSetId, updateRuleSet.getRuleSetId());
        List<Integer> oldRuleIdList = oldRuleList.stream().map(Rule::getRuleId).collect(Collectors.toList());
        List<Rule> addRuleList = new ArrayList<>();
        List<Rule> updateRuleList = new ArrayList<>();
        List<Condition> updateConditionList = new ArrayList<>();
        List<Condition> addConditionList = new ArrayList<>();
        List<List<Condition>> addRuleToAddConditionListList = new ArrayList<>();
        List<JSONObject> addRuleToPrepositionRuleDataList = new ArrayList<>();
        List<JSONObject> updateRuleToPrepositionRuleDataList = new ArrayList<>();
        List<Rule> ruleList = new ArrayList<>();
        for(int i = 0; i < ruleDataList.size();i++){
            JSONObject ruleData = ruleDataList.getJSONObject(i);
            Rule rule = new Rule();
            JsonConverter<Rule> ruleJsonConverter = new JsonConverter<>();
            rule = ruleJsonConverter.convert(ruleData, rule);
            if(oldRuleIdList.contains(rule.getRuleId())){
                if(ruleData.getJSONObject("prepositionRuleData").isEmpty()){
                    rule.setPrepositionRuleId(null);
                }
                Rule finalRule = rule;
                List<Condition> oldConditionListByRuleId = oldConditionList.stream().filter(c -> finalRule.getRuleId().equals(c.getRuleId())).collect(Collectors.toList());
                List<Integer> oldConditionIdListByRuleId = oldConditionListByRuleId.stream().map(Condition::getConditionId).collect(Collectors.toList());
                JSONArray conditionDataList = ruleData.getJSONArray("conditionDataList");
                for(int conditionIndex = 0; conditionIndex < conditionDataList.size();conditionIndex++){
                    JSONObject conditionData = conditionDataList.getJSONObject(conditionIndex);
                    Condition condition = new Condition();
                    JsonConverter<Condition> conditionJsonConverter = new JsonConverter<>();
                    condition = conditionJsonConverter.convert(conditionData, condition);
                    condition.setOrderId(conditionIndex + 1);
                    if(oldConditionIdListByRuleId.contains(condition.getConditionId())){
                        updateConditionList.add(condition);
                    }else{
                        condition.setRuleId(rule.getRuleId());
                        condition.setRuleSetId(updateRuleSet.getRuleSetId());
                        addConditionList.add(condition);
                    }
                }
                updateRuleList.add(rule);
                updateRuleToPrepositionRuleDataList.add(ruleData.getJSONObject("prepositionRuleData"));
            }else{
                handleAddRuleData(ruleData,updateRuleSet.getRuleSetId(),addRuleList,addRuleToAddConditionListList,addRuleToPrepositionRuleDataList);
            }
            ruleList.add(rule);
        }

        if(!addRuleSetParameterModuleList.isEmpty()){
            ruleSetParameterModuleService.saveBatch(addRuleSetParameterModuleList);
        }
        if(!deleteRuleSetParameterModuleIdList.isEmpty()){
            ruleSetParameterModuleService.removeByIds(deleteRuleSetParameterModuleIdList);
        }
        List<Rule> updatePrepositionRuleDataRuleList = new ArrayList<>();
        if(!addRuleList.isEmpty()){
            ruleService.insertBatch(addRuleList);
            handleConditionAndPrepositionRuleData(addRuleList,addRuleToAddConditionListList,addConditionList,addRuleToPrepositionRuleDataList,updatePrepositionRuleDataRuleList);
        }
        for(int i = 0; i < updateRuleList.size();i++){
            Rule rule = updateRuleList.get(i);
            JSONObject prepositionRuleData = updateRuleToPrepositionRuleDataList.get(i);
            Integer prepositionRuleId = prepositionRuleData.getInteger("value");
            if(prepositionRuleId != null){
                rule.setPrepositionRuleId(prepositionRuleId);
                continue;
            }
            String prepositionRuleName = prepositionRuleData.getString("label");
            if(StringUtils.isNotBlank(prepositionRuleName)){
                Rule prepositionRule = ruleList.stream().filter(r -> prepositionRuleName.equals(r.getRuleName())).findFirst().orElse(null);
                rule.setPrepositionRuleId(prepositionRule.getRuleId());
            }
        }
        List<Rule> updateAllRuleList = new ArrayList<>();
        updateAllRuleList.addAll(updatePrepositionRuleDataRuleList);
        updateAllRuleList.addAll(updateRuleList);
        if(!updateRuleList.isEmpty()){
            ruleService.updateBatchById(updateAllRuleList);
        }
        List<Integer> updateRuleIdList = updateRuleList.stream().map(Rule::getRuleId).collect(Collectors.toList());
        List<Integer> deleteRuleIdList = new ArrayList<>();
        for(Rule oldRule :oldRuleList){
            if(!updateRuleIdList.contains(oldRule.getRuleId())){
                deleteRuleIdList.add(oldRule.getRuleId());
            }
        }
        if(!deleteRuleIdList.isEmpty()){
            ruleService.removeByIds(deleteRuleIdList);
        }
        if(!addConditionList.isEmpty()){
            conditionService.saveBatch(addConditionList);
        }
        if(!updateConditionList.isEmpty()){
            conditionService.updateBatchById(updateConditionList);
        }
        List<Integer> updateConditionIdList = updateConditionList.stream().map(Condition::getConditionId).collect(Collectors.toList());
        List<Integer> deleteConditionIdList = new ArrayList<>();
        for(Condition oldCondition :oldConditionList){
            if(!updateConditionIdList.contains(oldCondition.getConditionId())){
                deleteConditionIdList.add(oldCondition.getConditionId());
            }
        }
        if(!deleteConditionIdList.isEmpty()){
            conditionService.deleteBatchByIds(deleteConditionIdList);
        }
    }

    /**
     * 处理新增规则数据
     * @param ruleData 规则数据
     * @param ruleSetId 规则集id
     * @param addRuleList 新增规则列表
     * @param ruleToAddConditionListList 规则对应新增条件列表列表
     * @param ruleToPrepositionRuleDataList  规则对应前置规则数据列表
     */
    public void handleAddRuleData(JSONObject ruleData, Integer ruleSetId, List<Rule> addRuleList, List<List<Condition>> ruleToAddConditionListList, List<JSONObject> ruleToPrepositionRuleDataList){
        Rule addRule = new Rule();
        JsonConverter<Rule> ruleJsonConverter = new JsonConverter<>();
        addRule = ruleJsonConverter.convert(ruleData, addRule);
        addRule.setRuleSetId(ruleSetId);
        JSONArray conditionDataList = ruleData.getJSONArray("conditionDataList");
        List<Condition> conditionList = new ArrayList<>();
        for(int conditionIndex = 0; conditionIndex < conditionDataList.size();conditionIndex++){
            JSONObject conditionData = conditionDataList.getJSONObject(conditionIndex);
            Condition condition = new Condition();
            JsonConverter<Condition> conditionJsonConverter = new JsonConverter<>();
            condition = conditionJsonConverter.convert(conditionData, condition);
            condition.setOrderId(conditionIndex + 1);
            condition.setRuleSetId(ruleSetId);
            conditionList.add(condition);
        }
        addRuleList.add(addRule);
        ruleToAddConditionListList.add(conditionList);
        ruleToPrepositionRuleDataList.add(ruleData.getJSONObject("prepositionRuleData"));
    }

    /**
     * 处理条件和前置规则数据
     * @param addRuleList 新增规则列表
     * @param addRuleToAddConditionListList 新增规则对应条件列表列表
     * @param addConditionList 新增条件列表
     * @param ruleToPrepositionRuleDataList 规则对应前置规则数据列表
     * @param updateRuleList 更新规则列表
     */
    public void handleConditionAndPrepositionRuleData(List<Rule> addRuleList,List<List<Condition>> addRuleToAddConditionListList,List<Condition> addConditionList,List<JSONObject> ruleToPrepositionRuleDataList,List<Rule> updateRuleList){
        for(int i = 0; i < addRuleList.size();i++){
            Rule rule = addRuleList.get(i);
            List<Condition> conditionList = addRuleToAddConditionListList.get(i);
            conditionList.forEach(c -> {
                c.setRuleId(rule.getRuleId());
                addConditionList.add(c);
            });
            JSONObject prepositionRuleData = ruleToPrepositionRuleDataList.get(i);
            Integer prepositionRuleId = prepositionRuleData.getInteger("value");
            if(prepositionRuleId != null){
                rule.setPrepositionRuleId(prepositionRuleId);
                continue;
            }
            String prepositionRuleName = prepositionRuleData.getString("label");
            if(StringUtils.isNotBlank(prepositionRuleName)){
                Rule prepositionRule = addRuleList.stream().filter(r -> prepositionRuleName.equals(r.getRuleName())).findFirst().orElse(null);
                rule.setPrepositionRuleId(prepositionRule.getRuleId());
                updateRuleList.add(rule);
            }
        }
    }

    /**
     * 根据模块ID和名称查询列表
     * @param ruleSetModuleId
     * @param ruleSetName
     * @return
     */
    public List<RuleSet> getListByModuleIdAndName(Integer ruleSetModuleId,String ruleSetName){
        return findByProperties(new String[]{"ruleSetModuleId","ruleSetName"},new Object[]{ruleSetModuleId,ruleSetName});
    }

    /**
     * 根据规则集ids删除规则集数据
     * @param ruleSetIds
     * @return
     */
    public JSONObject deleteByRuleSetIds(List<Integer> ruleSetIds){
        if (!ruleSetIds.isEmpty()){
            removeByIds(ruleSetIds);
            ruleService.removeByRuleSetIdList(ruleSetIds);
            conditionService.removeByRuleSetIdList(ruleSetIds);
        }
        return JsonUtil.getSuccess("");
    }

    /**
     * 获取模型(参数->变量)下拉框列表
     * @return
     */
    public JSONObject getModelOptionList(){
        List<ParameterModel> parameterModelList = parameterModelService.findAll();
        List<Integer> parameterModelIdList = parameterModelList.stream().map(ParameterModel::getModelId).collect(Collectors.toList());
        List<ParameterModule> parameterModuleList = parameterModuleService.getListByModelIdList(parameterModelIdList);
        List<JSONObject> parameterModelDataList = new ArrayList<>();
        for(ParameterModel parameterModel : parameterModelList){
            List<ParameterModule> parameterModuleListByModelId = parameterModuleList.stream().filter(p -> parameterModel.getModelId().equals(p.getParameterModelId())).collect(Collectors.toList());
            List<JSONObject> parameterModuleDataList = new ArrayList<>();
            for(ParameterModule parameterModule : parameterModuleListByModelId){
                JSONObject parameterModuleData = new JSONObject();
                parameterModuleData.fluentPut("value",parameterModule.getModuleId())
                        .fluentPut("label",parameterModule.getPropertyName() == null ? "" : parameterModule.getPropertyName());
                parameterModuleDataList.add(parameterModuleData);
            }
            JSONObject parameterModelData = new JSONObject();
            parameterModelData.fluentPut("value",modelIndex + optionValueSeparator + parameterModel.getModelId())
                    .fluentPut("label",parameterModel.getPropertyName() == null ? "" : parameterModel.getPropertyName());
            parameterModelData.put("children",parameterModuleDataList);
            parameterModelDataList.add(parameterModelData);
        }
        JSONObject data = new JSONObject();
        data.fluentPut("parameterModelDataList",parameterModelDataList);
        return JsonUtil.getSuccess("").fluentPut(APP.DATA,data);
    }

    /**
     * 加载规则集库列表
     * @param query
     * @return
     */
    public JSONObject loadGrid(JSONObject query){
        JSONArray jsonArray = new JSONArray();
        QueryWrapper<RuleSet> queryWrapper = new QueryWrapper<>();
        Integer ruleBaseType = query.getInteger("ruleBaseType");
        queryWrapper.lambda().eq(RuleSet::getRuleBaseType,ruleBaseType);
        if(query.getInteger("chipId") != null){
            queryWrapper.lambda().eq(RuleSet::getChipId,query.getInteger("chipId"));
        }
        String searchName = query.getString("searchName");
        if (StringUtils.isNotBlank(searchName)){
            queryWrapper.and(wrapper->{
                wrapper.lambda().like(RuleSet::getRuleSetName,searchName);
                wrapper.lambda().or().like(RuleSet::getRuleSetId,searchName);
            });
        }
        List<RuleSet> ruleSetList = list(queryWrapper);
        Set<Integer> driverLibraryIdSet = ruleSetList.stream().map(RuleSet::getDriverLibraryId).collect(Collectors.toSet());
        List<DriverLibrary> driverLibraryList = driverLibraryService.findListByIds(driverLibraryIdSet);
        for (RuleSet ruleSet : ruleSetList){
            JSONObject jsonData = new JSONObject();
            jsonData.put("ruleSetId",ruleSet.getRuleSetId());
            jsonData.put("ruleSetName",ruleSet.getRuleSetName());
            jsonData.put("updateTime",ruleSet.getUpdateTime());
            DriverLibrary driverLibrary = driverLibraryList.stream().filter(d -> d.getDriverLibraryId().equals(ruleSet.getDriverLibraryId())).findFirst().orElse(null);
            jsonData.put("compatible",driverLibrary == null || driverLibrary.getCompatible() == null ? "" : driverLibrary.getCompatible());
            jsonArray.add(jsonData);
        }
        return JsonUtil.getSuccess("").fluentPut(APP.DATA, jsonArray);
    }

    /**
     * 初始化参数配置规则集
     * @param webData
     * @return
     */
    public JSONObject initParameterConfiguration(JSONObject webData){
        Integer ruleSetId = webData.getInteger("ruleSetId");
        RuleSet ruleSet = findById(ruleSetId);
        if(ruleSet == null){
            return JsonUtil.getFail(ErrorCodeEnum.DATA_NOT_FOUND,"找不到对应的规则集数据");
        }
        List<Rule> ruleList = ruleService.findByProperty(Rule::getRuleSetId, ruleSetId);
        List<Condition> conditionList = conditionService.findByProperty(Condition::getRuleSetId, ruleSetId);
        JSONObject data = new JSONObject();
        data.fluentPut("ruleSetId",ruleSet.getRuleSetId())
                .fluentPut("ruleSetName",ruleSet.getRuleSetName() == null ? "" : ruleSet.getRuleSetName());
        List<JSONObject> ruleDataList = new ArrayList<>();
        Set<Integer> objectIdSet = ruleList.stream().map(Rule::getObjectId).collect(Collectors.toSet());
        List<ChipPin> chipPinList = new ArrayList<>();
        List<ChipInterface> chipInterfaceList = new ArrayList<>();
        List<ChipClockParameter> chipClockParameterList = new ArrayList<>();
        List<ChipPinParameter> chipPinParameterList = new ArrayList<>();
        List<ChipInterfaceParameter> chipInterfaceParameterList = new ArrayList<>();
        List<ChipParameter> chipParameterList = new ArrayList<>();
        if(RuleSetTypeEnum.CLOCK_CONFIGURATION.equals(ruleSet.getType())) {
            chipClockParameterList = chipClockParameterService.findByProperty(ChipClockParameter::getChipId, ruleSet.getChipId());
        }else if(RuleSetTypeEnum.PIN_CONFIGURATION.equals(ruleSet.getType())) {
            chipPinList = chipPinService.findListByIds(objectIdSet);
            chipPinParameterList = chipPinParameterService.findByProperty(ChipPinParameter::getChipId, ruleSet.getChipId());
        }else if(RuleSetTypeEnum.INTERFACE_RESOURCE_CONFIGURATION.equals(ruleSet.getType())){
            chipInterfaceList = chipInterfaceService.findListByIds(objectIdSet);
            List<Integer> interfaceIdList = chipInterfaceList.stream().map(ChipInterface::getInterfaceId).collect(Collectors.toList());
            chipInterfaceParameterList = chipInterfaceParameterService.getList(interfaceIdList);
        }else if(RuleSetTypeEnum.DRIVER_CONFIGURATION.equals(ruleSet.getType())){
            chipParameterList = chipParameterService.findByProperty(ChipParameter::getDriverLibraryId,ruleSet.getDriverLibraryId());
        }
        for(Rule rule : ruleList){
            JSONObject ruleData = new JSONObject();
            Rule prepositionRule = null;
            if(rule.getPrepositionRuleId() != null){
                prepositionRule = ruleList.stream().filter(r -> r.getRuleId().equals(rule.getPrepositionRuleId())).findFirst().orElse(null);
            }
            ConditionalRelationEnum conditionalRelationEnum = ConditionalRelationEnum.getEnumByValue(rule.getConditionalRelation());
            ruleData.fluentPut("ruleId",rule.getRuleId())
                    .fluentPut("ruleName",rule.getRuleName() == null ? "" : rule.getRuleName())
                    .fluentPut("prepositionRuleName",prepositionRule == null || prepositionRule.getRuleName() == null ? "" : prepositionRule.getRuleName())
                    .fluentPut("conditionalRelationName",conditionalRelationEnum == null ? "" : conditionalRelationEnum.getName())
                    .fluentPut("type",rule.getType() == null ? "" : rule.getType().getTypeId());
            List<Condition> conditionListByRuleId = conditionList.stream().filter(c -> rule.getRuleId().equals(c.getRuleId())).collect(Collectors.toList());
            List<JSONObject> conditionDataList = new ArrayList<>();
            String factModePrefix = "";
            if(RuleSetTypeEnum.PIN_CONFIGURATION.equals(ruleSet.getType())){
                ChipPin chipPin = chipPinList.stream().filter(c -> c.getPinId().equals(rule.getObjectId())).findFirst().orElse(null);
                factModePrefix = String.format("引脚%s参数",chipPin == null || chipPin.getPinCode() == null ? "" : chipPin.getPinCode()) ;
            }else if(RuleSetTypeEnum.INTERFACE_RESOURCE_CONFIGURATION.equals(ruleSet.getType())){
                ChipInterface chipInterface = chipInterfaceList.stream().filter(c -> c.getInterfaceId().equals(rule.getObjectId())).findFirst().orElse(null);
                factModePrefix = String.format("接口资源%s参数",chipInterface == null || chipInterface.getResourceName() == null ? "" : chipInterface.getResourceName());
            }
            for(Condition condition : conditionListByRuleId){
                //事实方式、标准规范表达式存的key为json文件的symbol，显示时需转换成parameter_name
                String factMode = condition.getFactMode() == null ? "" : condition.getFactMode();
                String standardSpecification = condition.getStandardSpecification() == null ? "" : condition.getStandardSpecification();
                List<? extends BaseChipParameter> baseChipParameterList = new ArrayList<>();
                if(RuleSetTypeEnum.CLOCK_CONFIGURATION.equals(ruleSet.getType())) {
                    baseChipParameterList = chipClockParameterList;
                }else if(RuleSetTypeEnum.PIN_CONFIGURATION.equals(ruleSet.getType())) {
                    baseChipParameterList = chipPinParameterList.stream().filter(c -> rule.getObjectId() != null && rule.getObjectId().equals(c.getPinId())).collect(Collectors.toList());
                }else if(RuleSetTypeEnum.INTERFACE_RESOURCE_CONFIGURATION.equals(ruleSet.getType())){
                    baseChipParameterList = chipInterfaceParameterList.stream().filter(c -> rule.getObjectId() != null && rule.getObjectId().equals(c.getInterfaceId())).collect(Collectors.toList());
                }else if(RuleSetTypeEnum.DRIVER_CONFIGURATION.equals(ruleSet.getType())){
                    baseChipParameterList = chipParameterList;
                }
                if(condition.getFactMode() != null){
                    String[] factModeSplit = factMode.split(",");
                    List<String> parameterNameList = new ArrayList<>();
                    for(String key : factModeSplit){
                        BaseChipParameter baseChipParameter = baseChipParameterList.stream().filter(c -> key.equals(c.getSymbol())).findFirst().orElse(null);
                        if(baseChipParameter == null){
                            parameterNameList.add(key);
                        }else{
                            String parameterName = baseChipParameter.getParameterName() == null ? "" : baseChipParameter.getParameterName();
                            parameterNameList.add(parameterName);
                        }
                    }
                    factMode = StringUtils.join(parameterNameList,",");
                }
                if(ComparatorEnum.SATISFY.getId().equals(condition.getComparator())){
                    String[] expressionSplit = standardSpecification.split("\\|\\||&&");
                    for(String singleExpression : expressionSplit) {
                        singleExpression = singleExpression.replace("(", "");
                        singleExpression = singleExpression.replace(")", "");
                        List<String> relationalOperatorList = RelationalOperatorEnum.getOperatorList();
                        String relationalOperatorJoin = StringUtils.join(relationalOperatorList, "|");
                        Pattern relationalOperatorPattern = Pattern.compile(relationalOperatorJoin);
                        Matcher relationalOperatorMatcher = relationalOperatorPattern.matcher(singleExpression);
                        if (relationalOperatorMatcher.find()) {
                            String operator = relationalOperatorMatcher.group();
                            String[] values = singleExpression.split(Pattern.quote(operator), 2);
                            if (values.length == 2) {
                                String leftValue = values[0].trim();
                                String rightValue = values[1].trim();
                                BaseChipParameter leftValueBaseChipParameter = baseChipParameterList.stream().filter(b -> leftValue.equals(b.getSymbol())).findFirst().orElse(null);
                                if(leftValueBaseChipParameter != null && leftValueBaseChipParameter.getParameterName() != null){
                                    String expression = leftValue + operator + rightValue;
                                    String expressionConvertResult = expression.replace(leftValue,leftValueBaseChipParameter.getParameterName());
                                    standardSpecification = standardSpecification.replace(expression,expressionConvertResult);
                                }
                            }
                        }
                    }

                }
                JSONObject conditionData = new JSONObject();
                ComparatorEnum comparatorEnum = ComparatorEnum.getEnumByValue(condition.getComparator());
                conditionData.fluentPut("conditionId",condition.getConditionId())
                        .fluentPut("factMode",factModePrefix + factMode)
                        .fluentPut("comparator",comparatorEnum == null ? "" : comparatorEnum.getName())
                        .fluentPut("orderId",condition.getOrderId());
                conditionData.put("standardSpecification",standardSpecification);
                conditionDataList.add(conditionData);
            }
            ruleData.put("conditionDataList",conditionDataList);
            ruleDataList.add(ruleData);
        }
        data.put("ruleDataList",ruleDataList);
        return JsonUtil.getSuccess("").fluentPut(APP.DATA,data);
    }



    /**
     * 生成参数配置规则集
     * @param userId
     * @param ruleSetName
     * @return
     */
    public RuleSet createParameterConfigurationRuleSet(Integer userId, String ruleSetName, Integer chipId) {
        RuleSet ruleSet = new RuleSet();
        ruleSet.setRuleSetName(ruleSetName);
        ruleSet.setUpdateTime(new Date());
        ruleSet.setCreatorId(userId);
        ruleSet.setChipId(chipId);
        ruleSet.setRuleBaseType(RuleBaseTypeEnum.PARAMETER_CONFIGURATION);
        return ruleSet;
    }

    /**
     * 新增参数配置规则集
     * @param ruleToConditionListData
     * @param dependenciesRuleToConfigurationRuleData
     * @param addRuleList
     * @param addConditionList
     */
    public void addParameterConfigurationRuleSet(Map<Rule, List<Condition>> ruleToConditionListData, Map<Rule, Rule> dependenciesRuleToConfigurationRuleData, List<Rule> addRuleList, List<Condition> addConditionList) {
        if(!addRuleList.isEmpty()){
            ruleService.insertBatchSomeColumn(addRuleList);
            for(Map.Entry<Rule, List<Condition>> entry: ruleToConditionListData.entrySet()){
                Rule rule = entry.getKey();
                List<Condition> conditionList = entry.getValue();
                for(Condition condition : conditionList){
                    condition.setRuleId(rule.getRuleId());
                }
            }
            List<Rule> updateRuleList = new ArrayList<>();
            for(Map.Entry<Rule, Rule> entry: dependenciesRuleToConfigurationRuleData.entrySet()){
                Rule dependenciesRule = entry.getKey();
                Rule configurationRule = entry.getValue();
                configurationRule.setPrepositionRuleId(dependenciesRule.getRuleId());
                updateRuleList.add(configurationRule);
            }
            if(!updateRuleList.isEmpty()){
                ruleService.updateBatchById(updateRuleList);
            }
        }
        if(!addConditionList.isEmpty()){
            conditionService.saveBatch(addConditionList);
        }
    }

    /**
     * 获取参数配置规则集列表
     * @param ruleSetList
     * @return
     */
    public JSONObject getParameterConfigurationRuleSetList(List<RuleSet> ruleSetList){
        List<JSONObject> dataList = new ArrayList<>();
        for(RuleSet ruleSet : ruleSetList){
            JSONObject ruleSetData = new JSONObject();
            ruleSetData.fluentPut("ruleSetId",ruleSet.getRuleSetId())
                    .fluentPut("ruleSetName",ruleSet.getRuleSetName() == null ? "" : ruleSet.getRuleSetName());
            dataList.add(ruleSetData);
        }
        return JsonUtil.getSuccess("").fluentPut(APP.DATA,dataList);
    }

    /**
     * 获取列表
     * @param chipId
     * @param ruleSetTypeIdList
     * @return
     */
    public List<RuleSet> getList(Integer chipId,List<Integer> ruleSetTypeIdList){
        if(ruleSetTypeIdList.isEmpty()){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<RuleSet> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(RuleSet::getChipId,chipId)
                .in(RuleSet::getType,ruleSetTypeIdList);
        return list(lambdaQueryWrapper);
    }

}
